Version 1.0, April 1998
The purpose of this part of the project is to test out the working of the stress meter, and to set up some software for your measurements, so that you can discover how best to collect some data. You also could find out how stable the system is, how much 'noise' there is, and whether the range of readings you can get is adequate.
It is not our purpose to teach you another computer language, it is just that QBASIC still provides a very convenient and easy-to-use method of testing any interface. It is also quite adequate for data collection in this simple type of equipment, and it is also far easier to use than a C programme. Once you have a working stress meter with a QBASIC programme to collect data, then try to translate Programme 3 of the three QBASIC programmes into Borland C++. This conversion to C++, counts for 20% of the project mark, it may be omitted if you (and your partner) are prepared to forego these marks and just use the QBASIC programmes provided. If you provide some significant improvements to the QBASIC, then extra marks will also be awarded. Any programmes must be documented properly, and working (compiled if C++) programmes presented on your floppy disk.
Type in, and store on your disk(s), the following programme. In this QBASIC programme : REM is a comment; CLS clears the screen (window); skinres is a variable into which the data is read via the STICK(0) function; PRINT writes this on the screen; line 50 reads a buffer to see if a key on the keyboard has been typed, if it has then the length of the string a$ will be 1, so the programme ends (exits) from line 60; lines 70/80 is an example of a software delay loop; on line 100 you have the infamous GOTO statement, to go back to Line 30 for another reading. Very useful here!
10 REM Biofeedback programme
1
20 CLS
30 skinres =
STICK(0)
40 PRINT skinres
50
a$ = INKEY$
60 IF LEN(a$) = 1 THEN
END
70 FOR delay = 1 TO 2000
80
NEXT delay
90 CLS
100
GOTO 30
The game port on the PC is a 15-way female connector. Attach your stress meter to the computer via this connection, run the programme. You may need to change the delay to either speed up or slow down the rate at which readings appear on the screen. Test the stress meter in open circuit, with the electrodes touching each other, and then attached to fingers. You may need to adjust the potentiometer VR1 so that the skin resistance readings are on-scale. The meter may function better if the readings are kept at lower values (<180). Now repeat the tests with Programme 2, a slightly more user-friendly version. However note that the line numbers have been removed, and the GOTO replaced by a DO...LOOP statement. Go through the programme code and make sure you understand what it is doing.{This was also explained for you during a lecture}
REM Biofeedback programme
2
CLS
PRINT "Press any key to end the
programme"
LOCATE 10, 23
PRINT "Skin
Resistance =
"
DO
skinres =
STICK(0)
LOCATE 10,
40
PRINT USING "####" STICK(0) 'Skinres
on game port
timex = TIMER + .2 'Delay
between readings in
seconds
DO
IF
INKEY$ > "" THEN END
LOOP UNTIL TIMER
> timex
LOOP
The next programme, Programme 3,
enables the data readings to be stored in the form of a text file on a floppy
disk, the file is called A:/BIOTEST.PRN. Go through the programme and work out
what the different statements are doing - the code is quite readable, and there
are already some comments (behind the ' marks on code lines).
REM Biofeedback programme
3
INPUT "Enter time between readings in seconds ",
t
CLS
OPEN "A:/BIOTEST.PRN" FOR APPEND
AS #1 'Create text output file on floppy disc
start =
TIMER
timex = TIMER
PRINT "Press any
key to end the programme"
LOCATE 10,
23
PRINT "Skin Resistance =
"
DO
skinres% = STICK(0)
'reads game port into variable skinres%
LOCATE
10, 40
PRINT USING "####"; STICK(0); 'Skinres
on game port
PRINT USING "####.##"; TIMER -
start;
PRINT "
seconds"
PRINT #1, USING "####.##"; TIMER -
start;
PRINT #1,
",";
PRINT #1, USING "####";
skinres%
timex = timex + t 'Delay between
readings in
seconds
DO
IF
INKEY$ > "" THEN END
LOOP UNTIL
TIMER > timex
LOOP
If you want to store other
files, for instance to compare data, then obviously you need to change the file
name. If you store data on the hard disk you will need to specify a directory
(and path), and also transfer it to your floppy disk when you finish. Please
don't leave it on the Tiger lab hard disks.
{Note that the corresponding function to outputs a byte, Data, from the computer to a particular port at Port_Address is OUTP(Port_Address, Data)}
Once the BASIC Programme 3 is working you can convert it into a simple C program to do the same thing. Using the BC++ system is much more complicated than using QBASIC, to start with a compilation step is needed since BC++ is compiled. Another order of magnitude of complexity enters if we want to put the program into a proper Windows environment. The purpose of this section is to introduce you to using C for low level input (or output), not to teach Windows programming.
You should set up your programs on your floppy disk. Choose Options, then Project.. and set the Source Directory to A:\ , if you don't have a floppy, set up a folder for yourself on C: as C:\<your initials>, remove this when you finish the exercises. Choose the Project menu, Select the New Project command. Enter hello.ide in the edit box requesting the project path and name. The dialog box also shows the name "hello" in the target name edit box. Also choose the Target type as EasyWin[.exe]
Click Advanced. Select the check box labelled .cpp Node. Ensure that the two check boxes labelled .rc and .def are unchecked. Click OK to create the new project file.
Click the hello.exe node to view the hello.cpp node (your source code file). Double click on this node to start the IDE editor. Enter a suitable program e.g.
// Yet another "hello world"
programChoose the Save As.. command in the
File menu. save your program as Hello.cpp on A:\ or the C:\<your
initials>
#include
<iostream.h>
main()
{
cout
<< "Hello Tiger World!!";
return
0;
}
Ctrl+F9 will compile, link and run the hello.exe program. This should (hopefully) introduce you to the programming environment for BC++. The Help menu is there for you to use if necessary, also the Borland C++ CDROM is available to view from the Tiger Server.
Whello is the Windows version of a 'Hello World' program, it can be found set up as a project, whello.ide, buried down in the directory : C:\ ..\examples\windows\whello. If you open up the whello.cpp program in the editor you can see that just setting up a 'hello world' type of program in BC++ (this is a C++ program now) is several orders of magnitude more complex than your previous experiences of programming, it has 275 lines of code. The complexity appears because we now need to control the Windows environment from our program. BC++ comes with a good selection of other ready-made programs for you to study, you don't need these today, but if you intend taking your programming skills further, then try running some of them at another time. One of these is a Mahjong game program. They provide excellent examples to illustrate C++ programming. A suitable book is 'Teach Yourself Borland C++ 4.5 in 21 Days", by N Shammas, C Arnush and E.Mulroy, Sams, 1995. There are also more recent releases of Borland C++ than 4.5.
In BC++ the library conio.h provides two functions inp(Port_address) and outp(Port_address, data) to input and output bytes of data from any input/output device at an address Port_address. Thus in BC++ line 30 of Programme 1 becomes
skinres = inp(Port_Address_Potentiometer_1)
You should have most of the information needed to write a BC++ programme, you can assume that the BC++ compiler supports the ANSI C libraries you met during the C programming course during the first part of COMS12301. You can use the same method for writing, compiling and running the programme that was used with the Hello programme.